package com.zbkj.front.config;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.LinkedHashMap;
import java.util.Map;

public class AlipayParamParser {
    private static final ObjectMapper mapper = new ObjectMapper();

    public static String parseOutTradeNo(String paramStr) throws Exception {
        // 1. 将参数字符串转换为Map
        Map<String, String> paramMap = parseParamString(paramStr);

        // 2. 直接获取out_trade_no字段
        return paramMap.get("out_trade_no");
    }

    private static Map<String, String> parseParamString(String paramStr) {
        Map<String, String> map = new LinkedHashMap<>();
        String[] pairs = paramStr.split("&");

        for (String pair : pairs) {
            int idx = pair.indexOf("=");
            String key = pair.substring(0, idx);
            String value = pair.substring(idx + 1);
            map.put(key, value);
        }
        return map;
    }

    public static void main(String[] args) throws Exception {
        String params = "gmt_create=2025-08-07 09:57:31&...&out_trade_no=XY2025080700000001000004";
        System.out.println("提取结果: " + parseOutTradeNo(params));
    }
}
